# To change this template, choose Tools | Templates
# and open the template in the editor.

from plugin import Plugin
from subprocess import *
import ConfigParser

__author__="vbuell"
__date__ ="$Apr 27, 2009 5:33:45 PM$"

class DesktopLinks(Plugin):
    capabilities = ['foo', 'info', 'check']

    def do_foo(self, name):
        return 'Hello %s!' % name

    def do_info(self):
        return 'Plugin for cleaning and '

    def do_check(self):
# TODO: use 'desktop-file-validate' for validation
# TODO: user mlocate for faster search
        p = Popen(["find ~/.local/share/applications/ ~/Desktop -name '*.desktop'"], shell=True, stdin=PIPE, stdout=PIPE)
        (child_stdout, child_stdin) = (p.stdout, p.stdin)
        lines = child_stdout.readlines()

        for line in lines:
            print line.strip()
            check_desktop_file(line.strip())


def is_exec_exists(exec_):
    # TODO
    pass

def check_desktop_file(filename):
#    f = open(filename,'r')
#    print f.read()

    config = ConfigParser.ConfigParser()
#    config.readfp(open(filename))
    config.read(filename)
    print config.get('Desktop Entry', 'Exec')
